package qst.com.bacK.mapper;

import org.apache.ibatis.annotations.*;
import qst.com.bacK.pojo.entity.Team;
import qst.com.bacK.pojo.entity.User;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

public interface UserMapper {
    // 查询 type  = 1 ,2 , 3 的用户
    @Select("select * from mbti.users")
    List<User> findAllUsersType();

    // 查询所有批次
    @Select("select * from mbti.class_teams")
    List<Team> findAllTeam();

    @Select("select * from mbti.users where login = #{loginCount}")
    User findUserByLoginCount(String loginCount);

    @Insert("insert into mbti.users(login,name,passwd,type,status) values(#{login},#{name},#{passwd},#{type},#{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(User u);

    @Update("update mbti.users set last_login = #{1} where id = #{0}")
    void updateLastLogin(Integer id, Timestamp timestamp);

    @Update("update mbti.users set passwd = #{1} where id = #{0}")
    void updatePassword(Integer id, String newPasswd);

    @Select("select * from mbti.users where  id = #{id}")
    User findUserByPassword(Integer id);

    @Select("select * from mbti.users where id = #{id}")
    User findById(Integer id);

    @Delete("delete from mbti.users where id = #{id}")
    void delete(int id);

    @Update("update mbti.users set login = #{login},name = #{name},type = #{type},status = #{status} where id = #{id}")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int update(User user) throws SQLException;

    @Select("select * from mbti.users where name like concat('%',#{name},'%')")
    List<User> findUserByLikeName(String name);
}
